﻿using LView.CMS.Componetns.Componetns;
using System;
using System.Web.Mvc;

namespace LView.CMS.API.Controllers
{
    [Route("api/[Controller]/[Action]")]
    public class AsposePdfController : Controller
    {
        private static AsposePdfComponetnt _component = new AsposePdfComponetnt();
        // GET: AsposePdf
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult GetTestAction()
        {
            return Content("Ok");
        }

        [HttpPost]
        public ActionResult TestAction(string name)
        {
            return Content($"Hello {name}");
        }

        [HttpPost]
        public ActionResult PdfToImage(string absoluteFilePath, string outputPath, string imgType)
        {
            try
            {
                switch (imgType)
                {
                    case "jpeg":
                        _component.ToJpeg(absoluteFilePath, outputPath);
                        break;
                    case "png":
                        _component.ToPng(absoluteFilePath, outputPath);
                        break;
                }
            }
            catch (Exception ex)
            {
                return Content("Fail");
            }
            return Content("Ok");
        }
    }
}